/**
 * 组件库入口
 * */

// 自定义组件
import qkImage from './qkImage'
import qkInput from './qkInput'
import qkGoods from "./qkGoods";
import qkStoreHeader from "./qkStoreHeader";
import qkStoreGoods from "./qkStoreGoods";
import qkAdvert from "./qkAdvert";
import qkTabbar from './qkTabbar';
import qkCarousel from './qkCarousel';
import qkStoreHotGoods from './qkStoreHotGoods';
import qkStoreActivity from './qkStoreActivity';
import qkStoreBanner from './qkStoreBanner';
import qkStoreSearch from './qkStoreSearch';

// 自定义组件属性

import qkImageAttr from './attr/qkImageAttr'
import qkInputAttr from './attr/qkInputAttr'
import qkGoodsAttr from "./attr/qkGoodsAttr";
import qkStoreHeaderAttr from "./attr/qkStoreHeaderAttr";
import qkStoreGoodsAttr from "./attr/qkStoreGoodsAttr";
import qkAdvertAttr from "./attr/qkAdvertAttr";
import qkTabbarAttr from './attr/qkTabbarAttr';
import qkCarouselAttr from './attr/qkCarouselAttr';
import qkStoreHotGoodsAttr from './attr/qkStoreHotGoodsAttr'
import qkStoreActivityAttr from './attr/qkStoreActivityAttr';
import qkStoreBnanerAttr from './attr/qkStoreBannerAttr';
import qkStoreSearchAttr from './attr/qkStoreSearchAttr';

// 所有自定义组件列表
const components = [
  qkImage,
  qkInput,
  qkGoods,
  qkStoreHeader,
  qkStoreGoods,
  qkAdvert,
  qkTabbar,
  qkCarousel,
  qkStoreHotGoods,
  qkStoreActivity,
  qkStoreBanner,
  qkStoreSearch,
]

// 所有自定义组件属性列表
const componentAttrs = [
  qkImageAttr, qkInputAttr,
  qkGoodsAttr,
  qkStoreHeaderAttr,
  qkStoreGoodsAttr,
  qkAdvertAttr,
  qkTabbarAttr,
  qkCarouselAttr,
  qkStoreHotGoodsAttr,
  qkStoreActivityAttr,
  qkStoreBnanerAttr,
  qkStoreSearchAttr,
]
// 定义 install 方法，接收 Vue 作为参数
const install = function (Vue) {
  // 判断是否安装，安装过就不继续往下执行
  if (install.installed) return
  install.installed = true
  // 遍历注册所有组件
  components.map(component => Vue.component(component.name, component))
  componentAttrs.map(component => Vue.component(component.name, component))

}

// 检测到 Vue 才执行，毕竟我们是基于 Vue 的
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

let _qk_register_components_object = {};
components.forEach(item => {
  _qk_register_components_object[item.name] = item
})
let _qk_register_components_object_attr = {};
componentAttrs.forEach(item => {
  _qk_register_components_object_attr[item.name] = item
})


export {
  _qk_register_components_object,
  _qk_register_components_object_attr,
}



export default {
  install,
  // 所有组件，必须具有 install，才能使用 Vue.use()
}
